﻿using System;
using System.Runtime.InteropServices;

namespace Moonlite.Modules.Editors.ImageViewer.Tga
{
    [StructLayout(LayoutKind.Sequential)]
    internal struct TgaHeaderInfo
    {
        public bool rle;
        public bool pal;
        public bool rgb;
        public bool grey;
        public bool supported;
        public TgaHeaderInfo(TgaHeader header)
        {
            rle = false;
            pal = false;
            rgb = false;
            grey = false;
            supported = true;
            switch (header.imageType)
            {
                case (byte)TgaType.TGA_TYPE_RLE_INDEXED:
                    rle = true;
                    if (header.colorMapType != 1 || header.colorMapSize != 24 || header.colorMapLength > 256)
                    {
                        supported = false;
                    }

                    pal = true;
                    break;
                case (byte)TgaType.TGA_TYPE_INDEXED:
                    if (header.colorMapType != 1 || header.colorMapSize != 24 || header.colorMapLength > 256)
                    {
                        supported = false;
                    }

                    pal = true;
                    break;
                case (byte)TgaType.TGA_TYPE_RLE_RGB:
                    rle = true;
                    rgb = true;
                    break;
                case (byte)TgaType.TGA_TYPE_RGB:
                    rgb = true;
                    break;
                case (byte)TgaType.TGA_TYPE_RLE_GREY:
                    rle = true;
                    grey = true;
                    break;
                case (byte)TgaType.TGA_TYPE_GREY:
                    grey = true;
                    break;
                default:
                    supported = false;
                    break;
            }
        }
    }
}
